package org.example.day13;

/**
 * 7.1.1 验证NEW、RUNNABLE、TERMINATED
 */
public class MyThread extends Thread{
    public MyThread() {
        //注意:这里的当前线程是main线程
        //构造方法中的状态: RUNNABLE ThreadName = main
        System.out.println("构造方法中的状态: " + Thread.currentThread().getState() + " ThreadName = " + Thread.currentThread().getName());
    }

    @Override
    public void run() {
        //run方法中的状态: RUNNABLE
        System.out.println("run方法中的状态: " + Thread.currentThread().getState());
    }

    public static void main(String[] args) {
        try {
            MyThread t = new MyThread();
            //main方法中的状态1: NEW
            System.out.println("main方法中的状态1: " + t.getState());
            Thread.sleep(1000);
            t.start();
            //main方法中的状态3: RUNNABLE
            System.out.println("main方法中的状态3: " + t.getState());
            Thread.sleep(1000);
            //main方法中的状态2: TERMINATED
            System.out.println("main方法中的状态2: " + t.getState());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
